package com.examples.mouse;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class AllMouseEvents {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		/* Creating a Display */
		Display display = Display.getDefault();

		/* Adding a Shell in the Display */
		Shell shell = new Shell(display);
		shell.setText("Shell");
		shell.setLayout(new FillLayout());

		/* Creating a label */
		Label label = new Label(shell, SWT.BORDER);
		label.setText("Name");
		label.pack();

		/* Creating a button */
		Button button = new Button(shell, SWT.PUSH);
		button.pack();
		button.setText("Button");
		button.setBounds(0, 20, 50, 20);

		/* Creating a Text field */
		Text text = new Text(shell, SWT.NONE);
		text.pack();

		AllMouseEventsListener allMouseEventsListener = new AllMouseEventsListener();

		/* Adding listeners */
		button.addMouseListener(allMouseEventsListener);
		label.addMouseMoveListener(allMouseEventsListener);
		text.addMouseTrackListener(allMouseEventsListener);
		shell.addMouseWheelListener(allMouseEventsListener);

		/* Setting the preferred size of the shell */
		shell.pack();

		/* Opening the shell */
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		//display.dispose(); //Commented only for SWTShowcase application.
	}

}
